---@class Tool
local M = {}
local Time = {}

---将RGB值转换为颜色
---@param r integer
---@param g integer
---@param b integer
---@param a integer? 默认255
---@return Color
function M.ToColor(r, g, b, a)
	---@type Color
	return {
		r = r,
		g = g,
		b = b,
		a = a or 255,
	}
end

---将XYZ值转换为3D坐标
---@param x number
---@param y number
---@param z number
---@return Vector3
function M.ToVector3(x, y, z)
	return {
		x = x,
		y = y,
		z = z,
	}
end

---执行函数
---@param id integer 唯一ID
---@param delay number 间隔时间(秒)
---@param func function 执行的函数
function M.TriggerInterval(id, delay, func)
	if not func or type(func) ~= "function" then return end
	if not delay or type(delay) ~= "number" or delay <= 0 then return end
	local currentTime = os.clock()
	if not Time[id] then Time[id] = 0 end
	if currentTime - Time[id] >= delay then
		Time[id] = currentTime
		func()
	end
end

return M
